home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / HARDWARE.SWG / 0035_Processor Speed Independe.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-25  |  2KB  |  64 lines

  1. {
  2. From: terjem@hda.hydro.com (Terje Mathisen)
  3.  
  4. >I need the source code to (in TP and/or Assembly) setup a processor
  5. >independant delay.  The one I have is way faster on a 486 than on a 386.
  6. >I need something that tests the machines speed when a unit is initialized
  7. >and saves a number to a variable and then a delay procedure that uses
  8. >that number.
  9.  
  10. Well, the Delay() procedure in the Crt unit is designed to do exactly this,
  11. but if you cannot use Crt, try this replacement which I wrote almost
  12. 10 years ago, and later converted to a Unit.
  13. }
  14.  
  15. {$R-,S-}
  16. Unit Delays;
  17.  
  18. INTERFACE
  19.  
  20. CONST loop_count : WORD = 250;
  21.  
  22. PROCEDURE Delay(ms : WORD);
  23.  
  24. IMPLEMENTATION
  25.  
  26. PROCEDURE Delay(ms : Word);
  27. BEGIN
  28. Inline(
  29.   $8B/$76/<MS            {    mov si,[bp<ms]}
  30.   /$09/$F6               {    or si,si}
  31.   /$74/$09               {    jz d2}
  32.   /$8B/$0E/>LOOP_COUNT   {d0: mov cx,[>loop_count]}
  33.   /$E2/$FE               {d1: loop d1}
  34.   /$4E                   {    dec si}
  35.   /$75/$F7               {    jnz d0}
  36. );                       {d2:}
  37. END;
  38.  
  39. BEGIN
  40. InLine(
  41.   $B8/$40/$00            {    mov ax,$40}
  42.   /$8E/$C0               {    mov es,ax}
  43.   /$BB/$6C/$00           {    mov bx,$6C}
  44.   /$26/$8B/$37           {d3: es: mov si,[bx]}
  45.   /$31/$FF               {    xor di,di}
  46.   /$26/$3B/$37           {d4: es: cmp si,[bx]}
  47.   /$74/$FB               {    je d4}
  48.   /$26/$8B/$37           {    es: mov si,[bx]}
  49.   /$8B/$0E/>LOOP_COUNT   {d5: mov cx,[>loop_count]}
  50.   /$E2/$FE               {d6: loop d6}
  51.   /$47                   {    inc di}
  52.   /$26/$3B/$37           {    es: cmp si,[bx]}
  53.   /$74/$F4               {    je d5}
  54.   /$A1/>LOOP_COUNT       {    mov ax,[>loop_count]}
  55.   /$F7/$E7               {    mul di}
  56.   /$B9/$37/$00           {    mov cx,55}
  57.   /$F7/$F1               {    div cx}
  58.   /$A3/>LOOP_COUNT       {    mov [>loop_count],ax}
  59.   /$81/$FF/$1E/$00       {    cmp di,30}
  60.   /$72/$D4               {    jb d3}
  61. );
  62. END.
  63.  
  64.